import java.util.Scanner;

public class Demo {
    //比较是单个子数组大,还是连续子数组大,返回其中一个
    public static int gets(int sum,int ret) {
        return sum > ret ? sum : ret;
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] array = new int[n];
        for(int i = 0; i < n;i++) {
            array[i] = scan.nextInt();
        }

        int sum = array[0];
        int max = array[0];

        for(int i = 1; i < n;i++) {
            sum = gets(sum+array[i],array[i]);
            if(max < sum) {
                max = sum;
            }
        }

        System.out.println(max);
    }
    public static boolean Flg(StringBuilder builder) {
        String str = builder.toString();
        int left = 0;
        int right = str.length()-1;

        while(left <= right) {
            if(str.charAt(left) == str.charAt(right)) {
                left++;
                right--;
            }else {
                return false;
            }
        }

        return true;
    }

    public static void main2(String[] args) {
        Scanner scan = new Scanner(System.in);
        String str1 = scan.nextLine();
        String str2 = scan.nextLine();
        StringBuilder builder = null;
        int count = 0;

        for(int i = 0; i < str1.length()+1;i++) {
            builder = new StringBuilder(str1);
            builder.insert(i,str2);
            boolean flg = Flg(builder);
            if(flg){
                count++;
            }
        }
        System.out.println(count);
    }
    public static void main1(String[] args) {

        Scanner scan = new Scanner(System.in);
        int m = scan.nextInt();
        int n = scan.nextInt();

        if(m == 0) {
            System.out.println(0);
        }
        boolean flg = false;
        String str = "0123456789ABCDEF";
        StringBuilder builder = new StringBuilder();

        if(m < 0) {
            m = - m;
            flg = true;
        }

        while(m > 0) {
            builder.append(str.charAt(m%n));
            m = m/n;
        }

        if(flg) {
            builder.append("-");
        }

        builder.reverse();
        System.out.println(builder);
    }
}
